﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>网站后台管理</title>
    <link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css" />
    <link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css" />
</head>
<body>
    <form class="layui-form column-content-detail">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <div class="layui-form-item">
                    <label class="layui-form-label">姓名：</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" required lay-verify="required" placeholder="请输入姓名" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">学校：</label>
                    <div class="layui-input-block">
                        <select name="school" lay-verify="required">
                            <option value="电子信息">电子信息</option>
                            <option value="中德大学">中德大学</option>
                            <option value="南开大学">南开大学</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">取件码：</label>
                    <div class="layui-input-block">
                        <input type="text" name="code" required lay-verify="required" placeholder="请输入取件码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">付款金额：</label>
                    <div class="layui-input-block">
                        <input type="number" name="price" required lay-verify="required" placeholder="请输入付款金额" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="padding-left: 10px;">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="order">确认修改</button>
            </div>
        </div>
    </form>
    <script src="../../static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../static/admin/js/common.js" type="text/javascript" charset="utf-8"></script>
    <script>
        layui.use(['form', 'layer', 'jquery'], function () {
            var form = layui.form(),
                $ = layui.jquery,
                layer = layui.layer;

            let reg = new RegExp("(^|&)id=([^&]*)(&|$)");
            let r = window.location.search.substr(1).match(reg);
            var tid = (unescape(r[2]));
            var index = layer.load();
            $.ajax({
                type: 'POST',
                url: '../../../controller/orderQuery.aspx',//发送请求
                data: {id:tid},
                dataType: 'JSON',
                success: function (res) {
                    console.log(res)
                    layer.close(index);
                    if (res.code == 200) {
                        $("input[name='name']").val(res.data.Name);
                        $("select[name='school']").find("option:contains(" + res.data.School + ")").attr("selected", true);
                        $("input[name='code']").val(res.data.Code);
                        $("input[name='price']").val(res.data.Price);
                    } else {
                        layer.open({
                            content: res.msg
                        });
                    }
                }
            });
            //监听提交
            form.on('submit(order)', function (data) {
                var index = layer.load();
                data.field.id = tid;
                console.log(data.field);
                $.ajax({
                    type: 'POST',
                    url: '../../../controller/orderEdit.aspx',//发送请求
                    data: data.field,
                    dataType: 'JSON',
                    success: function (res) {
                        layer.close(index);
                        if (res.code == 200) {
                            layer.msg(res.msg);
                        } else {
                            layer.open({
                                content: res.msg
                            });
                        }
                    }
                });
                return false;
            });
            form.render();
        });
    </script>
</body>
</html>